#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <chrono>
#include <iomanip>
#include "Bit.h"
#include "Bitstr.h"

#pragma once

using namespace std;

class Omvandla : Bitstr
{
public:

	Omvandla(void)
	{
	}

	~Omvandla(void)
	{
	}


	void tal_str(int tal, string &str, int nrbits)
	{
		int temp = abs(tal);
		str = "";
		while(nrbits > 0)
		{
			if(temp % 2)
			{
				str = '1' + str;
			}
			else
			{
				str = '0' + str;
			}
			if(temp > 0)
			{
				temp = temp/2;
			}
			nrbits--;
		}
		if(tal<0)
		{
			twokomp(str);
		}
	}


	int str_tal(string &str)
	{
		int storlek = str.length() - 1; 
		int tal = 0;
		int power = 0;
		bool positivOrNot = true;
		if(str[0] == '1')
		{
			positivOrNot = false;
			twokomp(str);
		}
		for (int i = storlek; i >= 0; i--)
		{
			if(str[i] == '1')
			{
				tal += pow(2, power);
			}
			power ++;
		}
		if(!positivOrNot)
		{
			tal = tal * (-1);
		}
		return tal;
	}

};

